package com.nulldev.util.io.nfs.demo.nplayer;

import java.awt.Desktop;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.nulldev.util.io.FileUtil;
import com.nulldev.util.io.nfs.nFile;
import com.nulldev.util.io.nfs.nFileSystem;
import com.nulldev.util.java.JVMUtil;

public class nFSPlayerDemo {

	public static void main(String[] args) throws IOException {
		final boolean write = false;
		if (write) {
			final nFileSystem nfs = new nFileSystem();
			nfs.addFile(new nFile("[redacted]", FileUtil.getResourceBytes(nFSPlayerDemo.class, "[redacted]")));
			nfs.addFile(new nFile("[redacted]", FileUtil.getResourceBytes(nFSPlayerDemo.class, "[redacted]")));
			nfs.toFile(FileUtil.safeCreate(FileUtil.HOME_DIRECTORY + "/nfs_playerdemo.nfs"));
		}else {
			final nFileSystem nfs = new nFileSystem(FileUtil.safeCreate(FileUtil.HOME_DIRECTORY + "/nfs_playerdemo.nfs"));
			nfs.__print_files();
			final boolean tapeA = true;
			if (tapeA) {
				final nFile jonesWave = nfs.getFile("joneswave.webm");
				final File fx = FileUtil.createTempFile(".webm");
				JVMUtil.async_println(fx.toString());
				final FileOutputStream fos = new FileOutputStream(fx);
				fos.write(jonesWave.getData());
				fos.flush();
				fos.close();
				Desktop.getDesktop().open(fx);
				try {
					Thread.sleep(1000L * 600);
				} catch (InterruptedException e) {
				}
			}else {
				final nFile skrill = nfs.getFile("[redacted]");
			}	
		}
	}

}
